<?php

namespace App\Listeners;

use App\Interfaces\UserInterface;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Overtrue\LaravelWeChat\Events\WeChatUserAuthorized;
//微信登陆事件
class EventListener
{
    protected  $user;
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct(UserInterface $user)
    {
        $this->user=$user;
    }

    /**
     * Handle the event.
     *
     * @param  Event  $event
     * @return void
     */
    public function handle(WeChatUserAuthorized $event)
    {
        //写入userinfo

        $app = \EasyWeChat::officialAccount();
        $userinfo = $app->user->get($event->user->id);
        $is_subscribe=0;
        if(isset($userinfo['subscribe'])&&$userinfo['subscribe']){
            $is_subscribe=1;
        }
        $this->user->createWechatUserByUserInfo($event->user->original,$is_subscribe);


    }
}
